define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'cookie'], function ($, undefined, Backend, Table, Form, Template, undefined) {
    $.cookie.prototype.defaults = {path: Config.moduleurl};
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'subject/category/index',
                    add_url: 'subject/category/add',
                    edit_url: 'subject/category/edit',
                    del_url: 'subject/category/del',
                    multi_url: 'subject/category/multi',
                    table: 'subject_category',
                }
            });

            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weight',
                sortOrder: 'desc',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),sortable:true},
                        {field: 'name', title: __('Name'), align: 'left', operate: 'LIKE' },
                        {field: 'weight', title: __('Weight'),sortable:true},
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);
            
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
            add: function () {
                Controller.api.bindevent();
                setTimeout(function () {
                    $("#c-type").trigger("change");
                }, 100);
            },
            edit: function () {
                Controller.api.bindevent();
            },
            del: function () {
                Controller.api.bindevent();
            },
            api: {
                bindevent: function () {
                    Form.api.bindevent($("form[role=form]"));
                }
            }
        };
        return Controller;
})